<template>
  <div class="svc-review">
    <div class="page-header">
      <h1>服务贡献审核</h1>
      <el-button type="primary" :loading="loading" @click="fetchAll">刷新</el-button>
    </div>

    <el-card>
      <el-table :data="rows" stripe v-loading="loading">
        <el-table-column prop="workType" label="类型" width="100" />
        <el-table-column prop="category" label="类别" width="220" />
        <el-table-column prop="content" label="内容" min-width="260" show-overflow-tooltip />
        <el-table-column prop="targetOrHours" label="目标/时长" width="140" />
        <el-table-column prop="status" label="状态" width="110">
          <template #default="{ row }"><el-tag :type="tag(row.status)">{{ text(row.status) }}</el-tag></template>
        </el-table-column>
        <el-table-column label="操作" width="200" fixed="right">
          <template #default="{ row }">
            <el-button type="text" @click="openReview(row)">审核</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>

    <el-dialog v-model="showReview" title="审核服务贡献" width="520px">
      <el-form :model="reviewForm" label-width="96px">
        <el-form-item label="审核结果" required>
          <el-radio-group v-model="reviewForm.status">
            <el-radio label="APPROVED">通过</el-radio>
            <el-radio label="REJECTED">驳回</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="审核意见">
          <el-input v-model="reviewForm.opinion" type="textarea" :rows="4" />
        </el-form-item>
      </el-form>
      <template #footer>
        <el-button @click="showReview=false">取消</el-button>
        <el-button type="primary" :loading="reviewLoading" @click="submitReview">提交</el-button>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import { getAllServices, reviewService } from '@/api/serviceContribution'

const rows = ref([])
const loading = ref(false)
const showReview = ref(false)
const reviewLoading = ref(false)
const currentId = ref(null)
const reviewForm = reactive({ status: '', opinion: '' })

function text(s){ return ({ PENDING:'待审核', APPROVED:'已通过', REJECTED:'已驳回' }[s] || '待审核') }
function tag(s){ return ({ PENDING:'warning', APPROVED:'success', REJECTED:'danger' }[s] || 'info') }

async function fetchAll(){ loading.value=true; try{ const res = await getAllServices({ status:'PENDING' }); rows.value = res?.data || res || [] } finally { loading.value=false } }
function openReview(row){ currentId.value = row.id; reviewForm.status=''; reviewForm.opinion=''; showReview.value=true }
async function submitReview(){ if(!reviewForm.status){ ElMessage.warning('请选择结果'); return } reviewLoading.value=true; try{ await reviewService(currentId.value, reviewForm); ElMessage.success('审核完成'); showReview.value=false; fetchAll() } finally { reviewLoading.value=false } }

onMounted(fetchAll)
</script>

<style scoped>
.svc-review { max-width: 1400px; }
.page-header { display:flex; justify-content:space-between; align-items:center; margin-bottom:16px; }
</style>


